package dawnland03.data.map.service;

import dawnland03.model.entity.Entity;
import dawnland03.data.map.model.Matrix;
import dawnland03.data.map.model.MatrixCell;
import dawnland03.data.map.algorithm.astar.MatrixOperations;

/**
 * User: Petru Obreja (obrejap@yahoo.com)
 * Date: Feb 5, 2010
 * Time: 2:45:13 PM
 */
public class MatrixOperationsImpl implements MatrixOperations {
    public double computeDistanceBetweenTwoNodes(Entity entity, Matrix matrix, MatrixCell a, MatrixCell b) {
        double x = Math.abs(a.getX() - b.getX());
        double y = Math.abs(a.getY() - b.getY());
        return Math.sqrt(x * x + y * y);
    }

    public double computeCostBetweenTwoNodes(Entity entity, Matrix matrix, MatrixCell start, MatrixCell end) {
        if(matrix.getMatrixDirectionBetweenTwoNeighbours(start, end) == null){
            return Double.MAX_VALUE;
        }
        return start.getCost() + end.getCost();
    }
}
